package model;

import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;

import javax.swing.JProgressBar;

import model.BinSetVariables;

/**
 * 
 * @author Estelle && Marie
 *
 * In this class, we set the functionality of each thread in the pool of thread for the simulation with thread
 */

public class CallablePrice implements Callable<Double>{

	
	BinSetVariables b;
	int z;
	Double res;
	ConcurrentHashMap<String, Long> nbOfThread;
	Random r = new Random();
	JProgressBar bar = new JProgressBar();
	
	/**
	 * Constructor of the class
	 * @param b
	 * @param z
	 * @param bar
	 */
	public CallablePrice(BinSetVariables b, int z, JProgressBar bar, ConcurrentHashMap<String, Long> n){
		
		this.b = b;
		this.z=z;
		this.bar=bar;
		this.nbOfThread = n;
		
	}
	
	/**
	 * Calculate the  price for one simulation
	 */
	
	@Override
	public Double call(){
		
		 nbOfThread.putIfAbsent("Thread "+ Thread.currentThread().getId(), Thread.currentThread().getId());
		
			double St = b.getS();
			
			for (int j=0; j< b.getnSteps(); j++){
				
				St = St*Math.exp( b.getDrift() + b.getvSqrdt() * (r.nextGaussian()));

			}				

			return Math.max(z*(St-b.getX()), 0);

		}
}

